#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include "HttpCgi.h"
#include "HttpEchoEngine.h"

using namespace std;
using namespace HttpFrame;
using namespace HttpFrame::Loger;

COperationEngine *pEngine=NULL;

int main(int argc,char *argv[])
{
    CLog log;

    log.log_open(HttpFrame::Loger::LOG_TRACE, HttpFrame::Loger::LOG_TYPE_CYCLE, "../log", "echo_log", 1024*10, 10);

    log.LOG_P(HttpFrame::Loger::LOG_ERROR,"begin run echo!\n");

    if(pEngine==NULL)
    {
        pEngine = new CEchoOperationEngine();
        if(pEngine==NULL)
        {
            log.LOG_P(HttpFrame::Loger::LOG_ERROR,"create CEchoOperationEngine false!\n");
            return -1;
        }
        
        log.LOG_P(HttpFrame::Loger::LOG_ERROR,"load config!...\n");
    
        CIniFile ini;
        if(ini.Open("../conf/echo.conf")!=true)
        {
            log.LOG_P(HttpFrame::Loger::LOG_ERROR,"open file:conf/echo.conf false!\n");
            return -2;
        }
    
        log.LOG_P(HttpFrame::Loger::LOG_ERROR,"pEngine->Init!...\n");
        if(pEngine->Init(ini))
        {
            log.LOG_P(HttpFrame::Loger::LOG_ERROR,"pEngine->Init false!\n");
            return -3;
        }
     }

    log.LOG_P(HttpFrame::Loger::LOG_ERROR,"cgi_process!...\n");
    
    int nRet = cgi_process(pEngine);

    log.LOG_P(HttpFrame::Loger::LOG_ERROR,"cgi_process ret=%d!\n",nRet);

    return nRet;
    
}


